Bite 25. No promo twice, keep state in a class
Login and get codingIn this bite a real world scenario: PyBites has a growing set of Bites and gives away promos. They choose a Bite randomly but don't want to choose the same one again.
Hence you are provided with a
BITES dictand aBITES_DONE setthat we use (copies) in thePromoclass via its constructor (code provided).Complete the following methods in the Promo class:
_pick_random_biteis a helper (_here means "private", not to be called directly on an instance) that picks a randomly available Bite (use therandommodule).
When no more Bites are available raise the providedNoBitesAvailablecustom exception.new_biteshould use this helper and updateself.bites_done(it keeps state, the reason we used a class here).See also the tests. We hope you learn a thing or two. Enjoy!
Update 4th of Nov 2020: we changed this Bite slightly to localize the Bite constants (thanks Kenneth). No worries: it's all done in the
__init__constructor for you, you don't have to change anything there).
457 out of 476 users completed this Bite.
Will you be the 458th person to crack this Bite?
Resolution time: ~48 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 5.58 on a 1-10 difficulty scale.
» Up for a challenge? 💪